;;;;
;; Packages
;;;;

;; Define package repositories
(require 'package)
;;(add-to-list 'package-archives
;;             '("tromey" . "http://tromey.com/elpa/") nil)
;;
;; (add-to-list 'package-archives
             ;; '("melpa-stable" . "https://stable.melpa.org/packages/") t)
;; (add-to-list 'package-archives
             ;; '("melpa-stable" . "http://elpa.emacs-china.org/melpa-stable/") t)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)
;;(add-to-list 'package-archives ;;             '("melpa" . "http://elpa.emacs-china.org/melpa/") t)


;; Load and activate emacs packages. Do this first so that the
;; packages are loaded before you start trying to modify them.
;; This also sets the load path.
(package-initialize)

;; Download the ELPA archive description if needed.
;; This informs Emacs about the latest versions of all packages, and
;; makes them available for download.
(when (not package-archive-contents)
  (package-refresh-contents))

;; Define he following variables to remove the compile-log warnings
;; when defining ido-ubiquitous
(defvar ido-cur-item nil)
(defvar ido-default-item nil)
(defvar ido-cur-list nil)
(defvar predicate nil)
(defvar inherit-input-method nil)

;; The packages you want installed. You can also install these
;; manually with M-x package-install
;; Add in your own as you wish:
(defvar my-packages
  '(;; makes handling lisp expressions much, much easier
    ;; Cheatsheet: http://www.emacswiki.org/emacs/PareditCheatsheet
    paredit

    ;; key bindings and code colorization for Clojure
    ;; https://github.com/clojure-emacs/clojure-mode
    clojure-mode

    ;; extra syntax highlighting for clojure
    clojure-mode-extra-font-locking

    ;; integration with a Clojure REPL
    ;; https://github.com/clojure-emacs/cider
    cider

    ;; allow ido usage in as many contexts as possible. see
    ;; customizations/navigation.el line 23 for a description
    ;; of ido
    ido-ubiquitous

    ;; Enhances M-x to allow easier execution of commands. Provides
    ;; a filterable list of possible commands in the minibuffer
    ;; http://www.emacswiki.org/emacs/Smex
    smex

    ;; project navigation
    projectile

    ;; colorful parenthesis matching
    rainbow-delimiters

    ;; edit html tags like sexps
    tagedit

    ;; git integration
    magit))

;; On OS X, an Emacs instance started from the graphical user
;; interface will have a different environment than a shell in a
;; terminal window, because OS X does not run a shell during the
;; login. Obviously this will lead to unexpected results when
;; calling external utilities like make from Emacs.
;; This library works around this problem by copying important
;; environment variables from the user's shell.
;; https://github.com/purcell/exec-path-from-shell
(if (eq system-type 'darwin)
    (add-to-list 'my-packages 'exec-path-from-shell))

(dolist (p my-packages)
  (when (not (package-installed-p p))
    (package-install p)))

;; Place downloaded elisp files in ~/.emacs.d/vendor. You'll then be able
;; to load them.
;;
;; For example, if you download yaml-mode.el to ~/.emacs.d/vendor,
;; then you can add the following code to this file:
;;
;; (require 'yaml-mode)
;; (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
;; 
;; Adding this code will make Emacs enter yaml mode whenever you open
;; a .yml file
(add-to-list 'load-path "~/.emacs.d/vendor")


;;;;
;; Customization
;;;;

;; Add a directory to our load path so that when you `load` things
;; below, Emacs knows where to look for the corresponding file.
(add-to-list 'load-path "~/.emacs.d/customizations")

;; Sets up exec-path-from-shell so that Emacs will use the correct
;; environment variables
(load "shell-integration.el")

;; These customizations make it easier for you to navigate files,
;; switch buffers, and choose options from the minibuffer.
(load "navigation.el")

;; These customizations change the way emacs looks and disable/enable
;; some user interface elements
(load "ui.el")

;; These customizations make editing a bit nicer.
(load "editing.el")

;; Hard-to-categorize customizations
(load "misc.el")

;; For editing lisps
(load "elisp-editing.el")

;; Langauage-specific
(load "setup-clojure.el")
(load "my-clojure-tools.el")
(load "setup-js.el")
(load "setup-python.el")
;;(load "setup-go.el")
(load "setup-org.el")
(load "setup-scheme.el")

;; load dictionary settings
(load "setup-dictionary.el")

;; setup rust
(load "setup-rust.el")

;; setup plantuml
(load "setup-plantuml.el")

;; An extensible vi layer fo Emacs
(add-to-list 'load-path "~/.emacs.d/plugins/evil")
(require 'evil)
(evil-mode 1)

;; set up auto save mode T.T
(setq auto-save-default 1)
(setq auto-save-timeout 5)

;;(add-to-list 'load-path "~/.emacs.d/plugins/slime")
(require 'slime)
;; set up slime
;;(setq inferior-lisp-program "/usr/bin/clisp")
;;(setq inferior-lisp-program "/opt/ccl/lx86cl64")
(if (string-equal "darwin" system-type)
    (setq inferior-lisp-program "/opt/ccl/dx86cl64"))
(if (string-equal "gnu/linux" system-type)
;    (setq inferior-lisp-program "/usr/bin/sbcl"))
    (setq inferior-lisp-program "/opt/ccl/lx86cl64"))
;		 (setq inferior-lisp-program "/usr/bin/clisp"))

(setq slime-contribs '(slime-fancy slime-company))
;;(setq temporary-file-directory "~/tmp")

;; reconfig C-SPC, which was conflict with input-methods key-bind
(global-unset-key (kbd "C-SPC"))
(global-set-key (kbd "M-SPC") 'set-mark-command)

;; setup cnfonts 
(cnfonts-enable)
(setq cnfonts-use-system-type t)

;; auto indent for emacs 24+
;; (electric-indent-mode 1)

;;(require 'elpy nil t)
;;(elpy-enable)

;; add this to make the font size adjust works.
(define-key special-event-map [config-changed-event] 'ignore)

;; set org mode src highlight
(setq org-src-fontify-natively t)


(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(coffee-tab-width 2)
 '(custom-safe-themes
   (quote
    ("b73a23e836b3122637563ad37ae8c7533121c2ac2c8f7c87b381dd7322714cd0" "7bc22d06a880362ab13cb3518b2f824cc6ed9bcbbb7647d71655b84b2d5e794d" "8db4b03b9ae654d4a57804286eb3e332725c84d7cdab38463cb6b97d5762ad26" "0dd2666921bd4c651c7f8a724b3416e95228a13fca1aa27dc0022f4e023bf197" "9e54a6ac0051987b4296e9276eecc5dfb67fdcd620191ee553f40a9b6d943e78" "c7737b9fc3471779c8e51ea0a37834d24aa80a0d6a79b215e7501227ada39855" default)))
 '(package-selected-packages
   (quote
    (racer rust-mode youdao-dictionary yaml-mode undo-tree typescript-mode tagedit swift-mode spark snazzy-theme smex slime-company sesman scala-mode request rainbow-delimiters prosjekt projectile paredit neotree monokai-theme magit kotlin-mode json-mode ido-ubiquitous hydandata-light-theme htmlize groovy-mode geiser faff-theme exec-path-from-shell elpy dirtree company-go cnfonts clojure-mode-extra-font-locking cider bash-completion atom-one-dark-theme atom-dark-theme async apropospriate-theme angular-mode alect-themes))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
